package com.aube.interact.model;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by huyaonan on 16/3/23.
 */
public class GoodsFavorListModel extends BaseModel {

    public GoodsGroup data;

    public int getSize() {
        if(data == null || data.goodsVoList == null)
            return 0;

        return data.goodsVoList.size();
    }

    public List<GoodsItem> getGoodsList() {
        if(getSize() > 0)
            return data.goodsVoList;
        return new ArrayList<>();
    }

    public GoodsItem get(int index) {
        return data.goodsVoList.get(index);
    }

    public void add(GoodsItem item) {
        if(data == null)
            data = new GoodsGroup();
        data.add(item);
    }

    public String getLastId() {
        if(data != null)
            return data.lastId;
        return null;
    }

    public static GoodsFavorListModel parse(String s) {
        GoodsFavorListModel response = new GoodsFavorListModel();
        try {
            JSONObject jsonObject = new JSONObject(s);
            JSONObject jsonData = jsonObject.optJSONObject("data");
            response.data = GoodsGroup.parse(jsonData);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return response;
    }

}
